package cn.ckx.coding.common.constant;

import cn.hutool.core.date.DateUtil;
import lombok.Data;

import java.util.Date;

/**
 * 周期枚举
 * 
 * @author kunxin.cai
 **/
public enum PeriodEnum {

    /**
     * 全部
     */
    ALL,
    /**
     * 年
     */
    YEAR,
    /**
     * 月
     */
    MONTH,
    /**
     * 周
     */
    WEEK,
    /**
     * 日
     */
    DAY;
    
    @Data
    public class PeriodDate{
        private Date startDate;
        private Date endTime;
    } 
    
    public PeriodDate getPeriodDate(){
        Date startDate = null;
        Date endTime = new Date();
        switch (this){
            case YEAR:
                startDate = DateUtil.beginOfYear(endTime);
                break;
            case MONTH:
                startDate = DateUtil.beginOfMonth(endTime);
                break;
            case WEEK:
                startDate = DateUtil.beginOfWeek(endTime);
                break;
            case DAY:
                startDate = DateUtil.beginOfDay(endTime); 
                break;
            case ALL:
                default:
        }
        PeriodDate periodDate = new PeriodDate();
        periodDate.setStartDate(startDate);
        periodDate.setEndTime(endTime);
        return periodDate; 
    }
    
}
